#pragma once

#include <iostream>
#include <functional>
#include <string>
#include "IntAddr.hpp"
class Reactor;

using handler_t = std::function<std::string(std::string &)>; //业务处理函数
using equeue_t = std::function<void(std::vector<std::pair<int,InetAddr>>*)>;

// 给每个fd提供一个缓冲区
class Connection
{
public:
    Connection() : _event(0), _owner(nullptr)
    {
    }

    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Expecter() = 0;
    virtual int GetSockfd() = 0;
    void SetEvent(const uint32_t &event)
    {
        _event = event;
    }
    uint32_t GetEvent()
    {
        return _event;
    }

    Reactor *GetOwner()
    {
        return _owner;
    }
    // 设置回指指针
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }
    void RegisterEqueue(equeue_t efunc)
    {
        _efunc = efunc;
    }
    ~Connection()
    {
    }

private:
    // 回指指针，指向Reactor
    Reactor *_owner;

    // 关心事件
    uint32_t _event;

public:
    // 回调函数
    // 业务
    handler_t _handler;

    // 获取普通描述符
    equeue_t _efunc;
};